<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增管理员</title>
<link rel="stylesheet" type="text/css" href="views/admin/style/css/basic.css" />
<link rel="stylesheet" type="text/css" href="views/admin/style/css/manager.css" />
<script type="text/javascript" src="views/common/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="views/common/js/artDialog4.1.6/jquery.artDialog.js?skin=idialog"></script>
<script type="text/javascript" src="views/common/js/artDialog4.1.6/plugins/iframeTools.js"></script>
<script type="text/javascript" src="views/common/js/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript" src="views/common/js/jquery-validation/localization/messages_zh.js"></script>
</head>
<body>
<script type="text/javascript">
/*******************************非插件写法*****************************
$(document).ready(function(){
    $("#user").focus(function(){
        $("#user ~ span").html('*');
    });
    $("#email").focus(function(){
        $("#email ~ span").html('*');
        $("#email").removeClass("input_error");
    });
    $("#passwd").focus(function(){
        $("#passwd ~ span").html('*');
        $("#email").removeClass("input_error");
    });
    $("#passwd2").focus(function(){
        $("#passwd2 ~ span").html('*');
        $("#email").removeClass("input_error");
    });
        $("#user").blur(function(){
        var user = $('#user').val();
        if(user == ''){
            $("#user").addClass("input_error");
            $("#user ~ span").html('用户名不得为空！');
            return false;
        }
        $.ajax({
            type:"POST",
            async:true,
            url:'?c=manage&m=isOne',
            data:"user=" + user,
            success:function(msg){
            if(msg == 'failed'){
                $("#user").addClass("input_error");
                $("#user ~ span").html('此用户名已被占用！');
                return false;
            }else if(msg == 'success'){
                $("#user").removeClass("input_error");
            }
            }
        
        });
    });
    $("#email").blur(function (){
        if($('#email').val() == ''){
            $("#email").addClass("input_error");
            $("#email ~ span").html('邮箱地址不得为空！');
            return false;
        }
    });
    $("#passwd").blur(function (){
        if($('#passwd').val() == ''){
            $("#passwd").addClass("input_error");
            $("#passwd ~ span").html('密码不得为空！');
            return false;
        }
    });
    $("#passwd2").blur(function (){
        if($('#passwd2').val() !== $('#passwd').val()){
            $("#passwd2").addClass("input_error");
            $("#passwd2 ~ span").html('密码和确认密码不一致！');
            return false;
        }
    });
    $("#level").change(function (){
        if($('#level').val() == '0'){
            $("#level").addClass("input_error");
            $("#level ~ span").html('您必须选择一个等级权限！');
            return false;
        }else{
            $("#level ~ span").html('*');
        }
    });
    $("#add_manage").click(function() {
    $.post("?c=manage&m=addSubmit", 
            { send: "add",
              user: $("#user").val(),
              email: $("#email").val(),
              passwd: $("#passwd").val(),
              passwd2: $("#passwd2").val(),
              level: $("#level").val()
            },
        function(msg){
            if(msg == 'success'){
                    art.dialog.tips('新增管理员成功！', 1);
                    setTimeout("location.href='?c=manage'",1200)
            } else if (msg == 'failed') {
                    art.dialog.tips('新增管理员失败！', 1.2);
            } else {
                    art.dialog({
                        title:'错误提示',
                        content: msg
                    }).lock();
            }
        }
    );
    });
});
*************************************************************************/
  $(document).ready(function(){
    $("#add_form").validate({
    submitHandler:function(){
        var data = $("#add_form").serialize();
        $.post("?c=manager&m=addSubmit&action=add", data,
            function(msg){
                if(msg == 'success'){
                    art.dialog.tips('新增管理员成功！', 1.5);
                    setTimeout(function(){
                        art.dialog.top.document.location.reload();
                    },1500);
                }else {
                    art.dialog.tips('新增管理员失败，请稍后重试！', 1.5);
                }
            }
        );
    },
    rules: {
	    user: {
	        required: true,
			minlength: 2,
            maxlength: 20,
            remote: "?c=manager&m=isOneByAjax"
		    },
        email: {
			required: true,
			email: true
            //remote: "?c=manage&m=isOne"
			},
        passwd: {
			required: true,
			minlength: 6
			},
		passwd2: {
			required: true,
			equalTo: "#passwd"
			},
        level: {
            required: true
        }
          },
    messages: {
        user: {
		    required: "请输入管理员用户名",
			minlength: "管理员用户名不能小于2位",
            maxlength: "管理员用户名不能大于20位",
            remote: "此用户名已被占用"
		},
        email: {
            required:"请输入您的邮箱地址"
            //remote: "此Email已被占用"
        },
        passwd: {
			required: "请输入密码",
			minlength: "密码长度不能小于6位"
		},
		passwd2: {
			required: "请再输入一遍密码",
			equalTo: "两次输入的密码不一致"
		},
        level: {
            required: "请选择一个管理员等级"
        }
    }
    });
  });
</script>
<form id="add_form" class="form">
    <div class="input_box">
        <div class="entry">
            <label for="user" class="title">用户名：</label>
            <span class="notice">*</span>
            <input type="text" name="user" class="form_input"/>
        </div>
        <div class="entry">
            <label for="email" class="title">Email地址：</label>
            <span class="notice">*</span>
            <input type="text" name="email" class="form_input" value=""/>
        </div>
        <div class="entry">
            <label for="passwd" class="title">密码：</label>
            <span class="notice">*</span>
            <input type="password" id="passwd" name="passwd" class="form_input"/>
        </div>
        <div class="entry">
            <label for="passwd2" class="title">密码确认：</label>
            <span class="notice">*</span>
            <input type="password" id="passwd2" name="passwd2" class="form_input"/>
        </div>
        <div class="entry">
            <label for="level" class="title">等级：</label>
            <span class="notice">*</span>
                <select name="level" >
                    <option value="">--请选择一个等级权限--</option>
                    <{html_options options=$allLevel}>
                </select>
        </div>
    </div>
    <div style="margin-left:160px;">
        <button type="submit" class="button">添加</button>
    </div>
</form>
</body>
</html>